package com.cardbaobao.cardbabyclient.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cardbaobao.cardbabyclient.R;
import com.cardbaobao.cardbabyclient.callback.ItemClickedCallback;
import com.cardbaobao.cardbabyclient.model.TransactionRecordData;
import com.cardbaobao.cardbabyclient.ui.adapter.base.CommonRecyclerAdapter;
import com.cardbaobao.cardbabyclient.ui.adapter.base.CommonRecyclerHolder;
import com.cardbaobao.cardbabyclient.utils.ImageLoaderUtil;
import com.cardbaobao.cardbabyclient.utils.URLUtil;

import java.util.List;

/**
 * Created by Jiangzx on 2017/9/13 11:32.
 */

public class WithdrawRecordAdapter extends CommonRecyclerAdapter<TransactionRecordData.ShowerBean> {
    public static final int TYPE_NO_DATA=-1;
    public static final int TYPE_NORMAL=0;
    private ItemClickedCallback<TransactionRecordData.ShowerBean> listener;

    public WithdrawRecordAdapter(Context context, List<TransactionRecordData.ShowerBean> data) {
        super(context, data, R.layout.item_withdraw_record);
    }

    public void setItemClickedCallback(ItemClickedCallback<TransactionRecordData.ShowerBean> listener){
        this.listener=listener;
    }

    @Override
    public void convert(CommonRecyclerHolder holder, final TransactionRecordData.ShowerBean item) {
        ImageLoaderUtil.displayImage(URLUtil.CBB_IMG_URL+item.getLogo(),
                (ImageView) holder.getView(R.id.iv_logo));
        holder.setTextViewText(R.id.tv_name,item.getChannel());
        holder.setTextViewText(R.id.tv_amount,item.getAmount());
        holder.setTextViewText(R.id.tv_time,item.getTime());
        holder.setTextViewText(R.id.tv_status,item.getStatus());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null){
                    listener.onItemClicked(item);
                }
            }
        });
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater=LayoutInflater.from(parent.getContext());
        if(viewType==TYPE_NO_DATA){
            View root=inflater.inflate(R.layout.item_no_data,parent,false);
            root.setVisibility(View.VISIBLE);
            ((ImageView)root.findViewById(R.id.iv_no_data_pic)).
                    setImageResource(R.mipmap.img_no_record);
            ((TextView)root.findViewById(R.id.tv_no_data_des)).
                    setText("无提现记录");
            return new RecyclerView.ViewHolder(root) {
            };
        }
        if(viewType==TYPE_NORMAL){
            View root=inflater.inflate(R.layout.item_withdraw_record,parent,false);
            return new CommonRecyclerHolder(root);
        }
        return null;
    }

    @Override
    public int getItemCount() {
        return (mData==null||mData.size()==0)?1:mData.size();
    }

    @Override
    public int getItemViewType(int position) {
        return (mData==null||mData.size()==0)?TYPE_NO_DATA:TYPE_NORMAL;
    }

}
